Skip to content

feat: add docsearch on deploy plugin - #244

Merged
calthejuggler merged 6 commits into
masterfrom
feature/docsearch-on-deploy-plugin
Jul 14, 2026
Merged

feat: add docsearch on deploy plugin#244
calthejuggler merged 6 commits into
masterfrom
feature/docsearch-on-deploy-plugin

Conversation

@calthejuggler

@calthejuggler calthejuggler commented Jan 26, 2026

Copy link
Copy Markdown
Collaborator

Previously, our DocSearch scraper was running immediately when a PR was merged. This creates a race condition where the scrape happens on the /previous/ version of the docs site - not the new one.

This PR adds a deployment plugin that, onSuccess, runs the search scraper.

What changed

  • New Netlify build plugin (plugins/trigger-algolia-scraper) that fires on onSuccess. On production deploys only, it dispatches the algolia.yml workflow via the GitHub API so the scraper runs against the freshly published site.
  • algolia.yml no longer triggers on push: master — it is now workflow_dispatch-only, driven by the plugin (also migrated the deprecated ::set-output to $GITHUB_OUTPUT).
  • build.yml reads the Node version from .nvmrc (node-version-file) instead of a hardcoded 20.x, and .nvmrc is bumped to 24.13.0.

Setup required (Netlify env var)

The plugin reads GITHUB_PAT from the Netlify build environment. This is not the GitHub Actions GITHUB_TOKEN (that only exists inside an Actions run; this plugin runs in Netlify's build). Provision it as:

  • The absmartly-bot account's token (not a personal PAT), ideally a fine-grained PAT scoped to actions: write on absmartly/docs only.
  • Scoped to the Production deploy context in Netlify. The plugin already no-ops outside production and skips gracefully if the token is missing, but scoping the secret is defense-in-depth.

How to test

  • Trigger a production deploy and confirm the Netlify deploy log shows Triggering Algolia scraper workflow... followed by the success status, and that a new Algolia workflow run appears in the Actions tab.
  • On a deploy preview / branch deploy, confirm the plugin logs the "not a production deploy" skip and does not dispatch.

Jira: N/A (docs-site CI/build tooling)

Summary by CodeRabbit

  • New Features
    • Added a Netlify plugin to manually trigger Algolia index updates via a CI workflow dispatch, running only for production deployments.
  • Chores
    • Updated the Node.js runtime version to 24.13.0.
    • Updated CI to read the Node.js version from the project version file.
    • Adjusted the Algolia workflow to support manual triggering and to use the current method for passing computed configuration between steps.

@coderabbitai

coderabbitai Bot commented Jan 26, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 581fe2b8-35ed-48f4-8360-66d269d94f21

📥 Commits

Reviewing files that changed from the base of the PR and between 2300699 and e4a8353.

📒 Files selected for processing (3)
  • .github/workflows/build.yml
  • plugins/trigger-algolia-scraper/index.js
  • plugins/trigger-algolia-scraper/package.json
🚧 Files skipped from review as they are similar to previous changes (1)
  • .github/workflows/build.yml

Walkthrough

The PR adds a production-gated Netlify plugin that dispatches the Algolia scraper workflow through GitHub Actions. It registers the plugin, updates the Algolia workflow for manual execution and modern output handling, and changes Node.js configuration to version 24.13.0 sourced from .nvmrc.

Estimated code review effort: 3 (Moderate) | ~22 minutes

Possibly related PRs

Suggested reviewers: bmsilva, marcio-absmartly, mario-silva

Poem

🐇 A rabbit twirls a plugin bright,
It wakes the scraper with one hop tonight,
Node twenty-four joins the flow,
Manual winds now make it go,
And Algolia dances light. 🥕

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title matches the main change: adding a deploy-time DocSearch plugin to trigger the scraper.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/docsearch-on-deploy-plugin

Comment @coderabbitai help to get the list of available commands.

@netlify

netlify Bot commented Jan 26, 2026

Copy link
Copy Markdown

Deploy Preview for absmartly-docs ready!

Name Link
🔨 Latest commit d56fb4f
🔍 Latest deploy log https://app.netlify.com/projects/absmartly-docs/deploys/697744b07f806800081cd837
😎 Deploy Preview https://deploy-preview-244--absmartly-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In `@plugins/trigger-algolia-scraper/index.js`:
- Around line 18-26: Wrap the GitHub dispatch fetch call in a try/catch and add
an AbortController-based timeout: create an AbortController, set a timeout (e.g.
setTimeout to call controller.abort after a configurable ms), pass
controller.signal into fetch, and in the catch block handle AbortError and other
network/DNS errors by logging the error and failing gracefully; also check
response.ok after fetch and log/throw with response status/body on non-2xx.
While editing plugins/trigger-algolia-scraper/index.js, update the payload ref
(currently "master") to use a configurable branch variable or confirm/replace
with your production branch name.
- Around line 16-27: The fetch call in plugins/trigger-algolia-scraper/index.js
hard-codes the workflow ref to "master"; replace the static ref in the body
passed to the dispatch fetch (the JSON.stringify({ ref: "master" }) argument)
with Netlify's BRANCH environment variable (e.g., use process.env.BRANCH,
falling back to "master" if unset) so the dispatched workflow uses the actual
deployed branch. Locate the fetch call and update the ref value in the request
body accordingly.

Comment on lines +16 to +27
console.log("Triggering Algolia scraper workflow...");

const response = await fetch(
"https://api.github.com/repos/absmartly/docs/actions/workflows/algolia.yml/dispatches",
{
method: "POST",
headers: {
Accept: "application/vnd.github+json",
Authorization: `Bearer ${token}`,
"X-GitHub-Api-Version": "2022-11-28",
},
body: JSON.stringify({ ref: "master" }),

@coderabbitai coderabbitai Bot Jan 26, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

# First, let's read the file to see the current state
cat -n plugins/trigger-algolia-scraper/index.js

Repository: absmartly/docs

Length of output: 1830


🏁 Script executed:

# Check for Netlify configuration files
find . -name "netlify.toml" -o -name "netlify.json" -o -name ".netlify" -type f | head -20

Repository: absmartly/docs

Length of output: 72


🏁 Script executed:

# Look for any deployment or CI/CD configuration
find . -name ".github" -o -name ".gitlab-ci.yml" -o -name "azure-pipelines.yml" -o -name ".circleci" | head -20

Repository: absmartly/docs

Length of output: 67


🏁 Script executed:

# Search for any references to BRANCH, HEAD, or other environment variables in the codebase
rg -i "process\.env\.(BRANCH|HEAD|DEPLOY)" --max-count 20

Repository: absmartly/docs

Length of output: 40


🏁 Script executed:

# Read the netlify.toml to check if multiple branches are deployed to production
cat netlify.toml

Repository: absmartly/docs

Length of output: 117


🏁 Script executed:

# Check the GitHub workflows
ls -la .github/workflows/

Repository: absmartly/docs

Length of output: 354


🏁 Script executed:

# Search for context or branch references in the entire codebase
rg -i "context.*production|branch" netlify.toml .github/ | head -30

Repository: absmartly/docs

Length of output: 2786


🏁 Script executed:

# Read the algolia.yml workflow to see what it expects
cat .github/workflows/algolia.yml

Repository: absmartly/docs

Length of output: 656


🏁 Script executed:

# Read the build.yml to check production deployment configuration
cat .github/workflows/build.yml

Repository: absmartly/docs

Length of output: 645


🏁 Script executed:

# Search for Netlify configuration related to production deployments
rg "production|branch" netlify.toml

Repository: absmartly/docs

Length of output: 40


🌐 Web query:

Netlify environment variables BRANCH production deploy

💡 Result:

On Netlify, “production vs branch deploy” is determined by the deploy context, not by whether BRANCH is set.

  • Detect production deploys

    • Use the built-in read-only env var CONTEXT:
      • CONTEXT=production for deploys from your site’s configured production branch
      • CONTEXT=branch-deploy for deploys from non-production branches
      • (also deploy-preview for PR previews, dev for Netlify Dev) [1][2]
  • What BRANCH means

    • BRANCH is a built-in read-only variable that contains the Git branch name being built (including on production deploys, where it will be your production branch like main) [2].
  • Setting different env var values for production vs branch deploys

    • In the Netlify UI you can set contextual values per deploy context (Production, Branch deploys, Deploy Previews, etc.) and optionally override for a specific branch (or a wildcard like release/*). The branch-specific value wins for that branch’s deploys. [3][4]
  • Doing it in netlify.toml

    • You can set context-specific env vars like:
      • [context.production.environment] for production
      • [context.branch-deploy.environment] for branch deploys
      • [context.<branchname>.environment] for a specific branch (most specific wins) [5]

Sources:
[1] Netlify Docs — Build environment variables (read-only CONTEXT, BRANCH)
[2] Netlify Docs — File-based configuration (context names and what “production” means)
[3] Netlify Docs — Environment variables overview (contextual values, branch overrides, wildcards)
[4] Netlify Blog — Introducing Deploy Contexts
[5] Netlify Docs — Get started with environment variables (netlify.toml context env examples)


Use the deployed branch name instead of hard-coding "master".

If production deploys from both the master and development branches (as shown in build.yml), dispatching the workflow to a static ref will fail on deployments from non-master branches. Use Netlify's BRANCH environment variable, which contains the actual Git branch being deployed:

♻️ Suggested ref handling
   const token = process.env.GITHUB_PAT;
   if (!token) {
     utils.status.show({
       title: "Algolia scraper trigger skipped",
       summary: "GITHUB_PAT environment variable is not set.",
     });
     return;
   }
 
+  const ref = process.env.BRANCH || "master";
   console.log("Triggering Algolia scraper workflow...");
@@
-      body: JSON.stringify({ ref: "master" }),
+      body: JSON.stringify({ ref }),
🤖 Prompt for AI Agents
In `@plugins/trigger-algolia-scraper/index.js` around lines 16 - 27, The fetch
call in plugins/trigger-algolia-scraper/index.js hard-codes the workflow ref to
"master"; replace the static ref in the body passed to the dispatch fetch (the
JSON.stringify({ ref: "master" }) argument) with Netlify's BRANCH environment
variable (e.g., use process.env.BRANCH, falling back to "master" if unset) so
the dispatched workflow uses the actual deployed branch. Locate the fetch call
and update the ref value in the request body accordingly.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deployments from development are not production deploys - only master should trigger the doc search scrape

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@calthejuggler, thank you for the clarification! You're absolutely right—if only master is deployed to the production context, then hard-coding ref: "master" is the correct approach. The CONTEXT === "production" check already ensures the workflow only triggers for production deploys from master, making the static ref appropriate for your deployment model.


✏️ Learnings added
Learnt from: calthejuggler
Repo: absmartly/docs PR: 244
File: plugins/trigger-algolia-scraper/index.js:16-27
Timestamp: 2026-01-26T10:45:26.591Z
Learning: In the absmartly/docs repository, only the `master` branch is deployed to Netlify's production context. Deployments from the `development` branch are not production deploys and should not trigger the Algolia DocSearch scraper.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

Comment thread plugins/trigger-algolia-scraper/index.js Outdated
@calthejuggler
calthejuggler force-pushed the feature/docsearch-on-deploy-plugin branch from d56fb4f to cc1943a Compare July 14, 2026 12:56
@calthejuggler
calthejuggler changed the base branch from development to master July 14, 2026 12:57
@netlify

netlify Bot commented Jul 14, 2026

Copy link
Copy Markdown

Deploy Preview for absmartly-docs ready!

Name Link
🔨 Latest commit e4a8353
🔍 Latest deploy log https://app.netlify.com/projects/absmartly-docs/deploys/6a5649891b893f0008e88df1
😎 Deploy Preview https://deploy-preview-244--absmartly-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@calthejuggler
calthejuggler force-pushed the feature/docsearch-on-deploy-plugin branch 2 times, most recently from 62e4fd0 to 2300699 Compare July 14, 2026 14:18

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.github/workflows/algolia.yml:
- Line 10: Disable persisted checkout credentials on both actions/checkout
steps: add persist-credentials: false in .github/workflows/algolia.yml at lines
10-10 and .github/workflows/build.yml at lines 13-13.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 22cc1bdb-86a6-41b1-9dfd-562dd9f04290

📥 Commits

Reviewing files that changed from the base of the PR and between d56fb4f and 2300699.

📒 Files selected for processing (3)
  • .github/workflows/algolia.yml
  • .github/workflows/build.yml
  • .nvmrc
🚧 Files skipped from review as they are similar to previous changes (1)
  • .nvmrc

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Inline review comments failed to post. This is likely due to GitHub's internal server error or limits when posting large numbers of comments. If you are seeing this consistently it is likely a permissions issue. Please check "Moderation" -> "Code review limits" under your organization settings.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.github/workflows/algolia.yml:
- Line 10: Disable persisted checkout credentials on both actions/checkout
steps: add persist-credentials: false in .github/workflows/algolia.yml at lines
10-10 and .github/workflows/build.yml at lines 13-13.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 22cc1bdb-86a6-41b1-9dfd-562dd9f04290

📥 Commits

Reviewing files that changed from the base of the PR and between d56fb4f and 2300699.

📒 Files selected for processing (3)
  • .github/workflows/algolia.yml
  • .github/workflows/build.yml
  • .nvmrc
🚧 Files skipped from review as they are similar to previous changes (1)
  • .nvmrc
🛑 Comments failed to post (1)
.github/workflows/algolia.yml (1)

10-10: 🔒 Security & Privacy | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

for f in .github/workflows/algolia.yml .github/workflows/build.yml; do
  echo "===== $f ====="
  nl -ba "$f" | sed -n '1,120p'
done

Repository: absmartly/docs

Length of output: 234


🏁 Script executed:

#!/bin/bash
set -euo pipefail

for f in .github/workflows/algolia.yml .github/workflows/build.yml; do
  echo "===== $f ====="
  awk 'NR>=1 && NR<=120 { printf "%4d  %s\n", NR, $0 }' "$f"
done

Repository: absmartly/docs

Length of output: 1724


Disable persisted checkout credentials in both workflows.

actions/checkout leaves the repository token in git config by default, so later steps can reuse it. Set persist-credentials: false on both checkout steps:

  • .github/workflows/algolia.yml:10
  • .github/workflows/build.yml:13
🧰 Tools
🪛 zizmor (1.26.1)

[warning] 10-10: credential persistence through GitHub Actions artifacts (artipacked): does not set persist-credentials: false

(artipacked)

📍 Affects 2 files
  • .github/workflows/algolia.yml#L10-L10 (this comment)
  • .github/workflows/build.yml#L13-L13
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.github/workflows/algolia.yml at line 10, Disable persisted checkout
credentials on both actions/checkout steps: add persist-credentials: false in
.github/workflows/algolia.yml at lines 10-10 and .github/workflows/build.yml at
lines 13-13.

Source: Linters/SAST tools

@Pedro-Revez-Silva Pedro-Revez-Silva left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good overall. I’m approving with one non-blocking P2 reliability concern inline.

Comment on lines +33 to +39
} catch (error) {
console.error("Failed to reach the GitHub API:", error.message);
utils.status.show({
title: "Algolia scraper trigger failed",
summary: `Could not reach the GitHub API: ${error.message}`,
});
return;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Please make scraper-dispatch failures operationally visible. A missing token, a network/timeout error here, or the non-2xx path below currently only calls utils.status.show(...) and returns. Now that the push: master trigger is removed, that can leave search stale with no failed GitHub workflow or automatic retry. I’d retry transient failures and then call utils.build.failPlugin(...) (or provide equivalent alerting). This does not need to block this PR if best-effort indexing is intentional, but that behavior should be an explicit operational choice.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done 🙂

@calthejuggler
calthejuggler force-pushed the feature/docsearch-on-deploy-plugin branch from 2300699 to e4a8353 Compare July 14, 2026 14:36
@calthejuggler
calthejuggler merged commit b487493 into master Jul 14, 2026
6 checks passed
@calthejuggler
calthejuggler deleted the feature/docsearch-on-deploy-plugin branch July 14, 2026 15:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants